import { AlertController } from '@ionic/angular';
import { Component, OnInit } from '@angular/core';

import { pb } from 'src/pb';
import { FileService } from '../services/file.service';
import { SettingsService } from '../services/settings.service';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
  folder: pb.IFolder;
  constructor(
    private fs: FileService,
    private ss: SettingsService,
    private alertCtrl: AlertController,
  ) {
  }

  async ngOnInit() {
    this.folder = await this.fs.folder();
  }

  refresh(ev) {
    setTimeout(() => {
      ev.detail.complete();
    }, 3000);
  }

  async about() {
    const alert = await this.alertCtrl.create({
      header: 'Reader',
      subHeader: '远程文件阅读器',
      message: `版本: ${this.ss.config.version}<br>
提交: ${this.ss.config.gitCommit}<br>
日期: ${this.ss.config.buildTime}`,
      buttons: ['关闭']
    });
    await alert.present();
  }
}
